//---------------------------------------------------------------------
// Authors: jachymko
//
// Description: Base class for all filesystem link commands.
//
// Creation Date: Dec 13, 2006
//
//---------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.IO;
using System.Management.Automation;
using System.Runtime.InteropServices;

namespace Pscx.Commands.FileSystem
{
    public partial class LinkCommandBase : PSCmdlet
    {
        string _path;

        [Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true,
                   HelpMessage = "Path to the new link.")]
        [AcceptsWildcards(false)]
        [ValidateNotNullOrEmpty]
        public string Path
        {
            set { _path = value; }
            get { return _path; }
        } 

        protected string FullPath
        {
            get { return GetUnresolvedProviderPathFromPSPath(_path); }
        }

        protected FileSystemInfo FindFileOrDirectory(string path)
        {
            FileInfo fi = new FileInfo(path);
            
            if(fi.Exists)
                return fi;

            DirectoryInfo di = new DirectoryInfo(path);
            if(di.Exists)
                return di;

            return null;
        }
    }

    public partial class NewLinkCommandBase : LinkCommandBase
    {
        string _target;

        [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true,
                   HelpMessage = "Target of the link.")]
        [AcceptsWildcards(false)]
        [ValidateNotNullOrEmpty]
        public string Target
        {
            set { _target = value; }
            get { return _target; }
        }

        protected string FullTarget
        {
            get { return GetUnresolvedProviderPathFromPSPath(_target); }
        }
    }
}
